﻿using System;
using System.Drawing;

using Storm.TextEditor.Editor.Text;
using Storm.TextEditor.Parser.Objects;

namespace Storm.TextEditor.Drawing
{
    /// <summary>
    /// Defines a TextEditor painter class.
    /// </summary>
    public interface IPainter
        : IDisposable
    {
        /// <summary>
        /// Renders all enabled features of the TextEditor.
        /// </summary>
        void RenderAll();

        /// <summary>
        /// Renders all enabled features of the TextEditor.
        /// </summary>
        /// <param name="g">Graphics to use when drawing.</param>
        void RenderAll(Graphics g);

        /// <summary>
        /// Renders the caret of the TextEditor.
        /// </summary>
        /// <param name="g">Graphics to use when drawing.</param>
        void RenderCaret(Graphics g);

        /// <summary>
        /// Renders the row at the given index.
        /// </summary>
        /// <param name="index">Index of the row to render.</param>
        void RenderRow(int index);

        /// <summary>
        /// Called by the TextEditor when it is resized - reinitializes the graphics of the IPainter.
        /// </summary>
        void Resize();

        /// <summary>
        /// Initializes the graphics of the IPainter.
        /// </summary>
        void InitGraphics();

        /// <summary>
        /// Returns the maximum character width of the current font.
        /// </summary>
        /// <returns>The maximum character width of the current font.</returns>
        int GetMaxCharWidth();

        /// <summary>
        /// Measures the given row.
        /// </summary>
        /// <param name="row">Row to measure.</param>
        /// <param name="count"></param>
        /// <returns>Size of the measures row.</returns>
        Size MeasureRow(Row row, int count);

        /// <summary>
        /// Measures the given string.
        /// </summary>
        /// <param name="str">String to measure.</param>
        /// <returns>Size of the measured string.</returns>
        Size MeasureString(string str);

        /// <summary>
        /// Returns a TextPoint representing the X and Y coordinates, except as a valid position in the TextEditor.
        /// </summary>
        /// <param name="x">X coordinate.</param>
        /// <param name="y">Y coordinate.</param>
        /// <returns>A TextPoint representing the X and Y coordinates, except as a valid position in the TextEditor.</returns>
        TextPoint GetTextPointAtPixel(int x, int y);

        /// <summary>
        /// Returns a Point representing the given TextPoint, except as a valid position in the screen.
        /// </summary>
        /// <param name="textPoint">TextPoint to convert to a valid Point.</param>
        /// <returns>A Point representing the given TextPoint, except as a valid position in the screen.</returns>
        Point GetPixelAtTextPoint(TextPoint textPoint);
    }
}
